package com.gitee.wsl.android.ui.theme.local

import android.graphics.Color
import com.gitee.wsl.android.ui.R
import com.gitee.wsl.common.ui.theme.ComposeColorPaletteScheme
import com.gitee.wsl.android.ext.ApplicationInit.application
import com.gitee.wsl.common.ui.theme.local.Material3ColorPalette
import com.google.android.material.color.MaterialColors


operator fun Material3ColorPalette.get(shade: Double): Color {
    val colorLong = when (shade) {
        0.0  -> this.`0`
        10.0 -> this.`10`
        20.0 -> this.`20`
        30.0 -> this.`30`
        40.0 -> this.`40`
        50.0 -> this.`50`
        60.0 -> this.`60`
        70.0 -> this.`70`
        80.0 -> this.`80`
        90.0 -> this.`90`
        95.0 -> this.`95`
        100.0 -> this.`100`
        else -> this.`90`
    }
    return Color.valueOf(colorLong)
}

fun getSystemColor(id:Int,defaultValue:Long=0):Long = MaterialColors.getColor(application, id,defaultValue.toInt()).toLong()

fun getCompatSystemColor(id:Int,defaultValue:Long=0):Long = MaterialColors.getColor(application, id,defaultValue.toInt()).toLong()

val SystemTheme: ComposeColorPaletteScheme<Long> by lazy {
    object: ComposeColorPaletteScheme<Long> {
        override var primary =                     getSystemColor(android.R.attr.colorPrimary)
        override var onPrimary =                   getSystemColor(R.attr.colorOnPrimary)
        override var primaryContainer =            getSystemColor(R.attr.colorPrimaryContainer)
        override var onPrimaryContainer =          getSystemColor(R.attr.colorOnPrimaryContainer)
        override var secondary =                   getSystemColor(android.R.attr.colorSecondary)
        override var onSecondary =                 getSystemColor(R.attr.colorOnSecondary)
        override var secondaryContainer =          getSystemColor(R.attr.colorSecondaryContainer)
        override var onSecondaryContainer =        getSystemColor(R.attr.colorOnSecondaryContainer)
        override var tertiary =                    getSystemColor(R.attr.colorTertiary)
        override var onTertiary =                  getSystemColor(R.attr.colorOnTertiary)
        override var tertiaryContainer =           getSystemColor(R.attr.colorTertiaryContainer)
        override var onTertiaryContainer =         getSystemColor(R.attr.colorOnTertiaryContainer)
        override var error =                       getSystemColor(R.attr.colorError)
        override var onError =                     getSystemColor(R.attr.colorOnError)
        override var errorContainer =              getSystemColor(R.attr.colorErrorContainer)
        override var onErrorContainer =            getSystemColor(R.attr.colorOnErrorContainer)
        override var outline =                     getSystemColor(R.attr.colorOutline)
        override var background =                  getSystemColor(android.R.attr.colorBackground)
        override var onBackground =                getSystemColor(R.attr.colorOnBackground)
        override var surface =                     getSystemColor(R.attr.colorSurface)
        override var onSurface =                   getSystemColor(R.attr.colorOnSurface)
        override var surfaceVariant =              getSystemColor(R.attr.colorSurfaceVariant)
        override var onSurfaceVariant =            getSystemColor(R.attr.colorOnSurfaceVariant)
        override var inverseSurface =              getSystemColor(R.attr.colorSurfaceInverse)
        override var inverseOnSurface =            getSystemColor(R.attr.colorOnSurfaceInverse)
        override var inversePrimary =              getSystemColor(R.attr.colorPrimaryInverse)
        override var shadow =                      getSystemColor(android.R.attr.shadowColor)
        override var surfaceTint =                 getSystemColor(R.attr.colorSurface)
        override var outlineVariant =              getSystemColor(R.attr.colorOutline)
        override var scrim =                       getSystemColor(R.attr.colorOnTertiary)

        override var textColorPrimary: Long = getSystemColor(android.R.attr.textColorPrimary)
        override var textColorPrimaryInverse: Long =  getSystemColor(android.R.attr.textColorPrimaryInverse)
        override var textColorSecondary: Long = getSystemColor(android.R.attr.textColorSecondary)
        override var textColorSecondaryInverse: Long = getSystemColor(android.R.attr.textColorSecondaryInverse)
        override var textColorTertiary: Long = getSystemColor(android.R.attr.textColorTertiary)
        override var textColorTertiaryInverse: Long = getSystemColor(android.R.attr.textColorTertiaryInverse)
        override var textColorPrimaryDisableOnly: Long = getSystemColor(android.R.attr.textColorPrimaryDisableOnly)
        override var textColorPrimaryInverseDisableOnly: Long = getSystemColor(android.R.attr.textColorPrimaryInverseDisableOnly)
        override var textColorHint: Long = getSystemColor(android.R.attr.textColorHint)
        override var textColorHintInverse: Long = getSystemColor(android.R.attr.textColorHintInverse)
        override var textColorHighlight: Long = getSystemColor(android.R.attr.textColorHighlight)
        override var textColorHighlightInverse: Long = getSystemColor(android.R.attr.textColorHighlightInverse)
        override var textColorLink: Long = getSystemColor(android.R.attr.textColorLink)
        override var textColorLinkInverse: Long = getSystemColor(android.R.attr.textColorLinkInverse)
        override var textColorAlertDialogListItem: Long = getSystemColor(android.R.attr.textColorAlertDialogListItem)
    }
}